<div class="page-header row">
    <h1 class="pull-left">My Account</h1>
    <?php echo anchor('account/logout', 'Logout', array('class' => 'pull-right', 'style' => 'margin-top: 15px;')); ?>
</div>

<h3>Raffle Draw</h3>
<div class="alert-message block-message info">
    <p>It seems that you haven't generated a raffle number yet. Click the <strong>Generate</strong> button below to join the raffle.</p>
    <div class="alert-actions">
        <span class="btn small joinRaffle">Generate</span>
        <span class="btn small viewRaffle">View Raffle Entries</span>
    </div>
</div>

<h3>Change Password</h3>
<?php echo form_open('account/update_profile'); ?>
    <div class="clearfix">
        <label>Password</label>
        <div class="input">
            <input type="password" name="password" />
            <span class="help-block">Leave this blank if you don't want to change your password.</span>
            <span class="help-block">Password should be at least six (6) characters.</span>
        </div>
    </div>
    <div class="clearfix">
        <label>Confirm Password</label>
        <div class="input">
            <input type="password" name="password2" />
        </div>
    </div>
    <div class="actions clearfix">
        <button type="submit" class="btn primary">Submit</button>
        <span class="btn resetForm">Reset</span>
    </div>
</form>





<script>
    $('form').submit(function() { return false; })
    
    $('form button').click(function() {
        var form = $(this).parents('form');
        
        form.find('.alert-message').remove();
        
        $.ajax({
            type: 'post',
            url: form.attr('action'),
            data: form.serialize(),
            dataType: 'json',
            success: function(data)
            {
                var div = $('<div />').addClass('alert-message');
                div.append($('<span />').addClass('close').html('&times;'));
                
                if (data.success == true)
                {
                    div.addClass('success');
                    div.append(data.text);
                    form.find('input').val('');
                }
                else
                {
                    div.addClass('error');
                    div.append(data.errors);
                }
                
                div.hide().prependTo(form).fadeIn();
            }
        });
        
        return false;
    });
    
    
    
    $('.joinRaffle').click(function() {
        
        var p = $(this).parents('.alert-message');
        
        p.siblings('.alert-message').remove();
        
        $.ajax({
            type: 'post',
            url: '<?php echo site_url('account/join_raffle'); ?>',
            dataType: 'json',
            success: function(data)
            {
                if (data.success == true)
                {
                    
                }
                else
                {
                    var div = $('<div />').addClass('alert-message warning');
                    div.append($('<span />').addClass('close').html('&times;'));
                    div.append(data.errors);
                    div.hide().insertBefore(p).fadeIn();
                }
            }
        });
        
        return false;
    });
    
</script>